package com.api.phm.domain.model;

import com.alibaba.fastjson2.JSONObject;
import com.api.common.core.domain.BaseEntity;
import com.api.common.language.LanguageBean;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@Data
public class AllDevicesModel extends BaseEntity {
    private Long lineId;
    private String lineName;
    private JSONObject lineNameJson;
    private Long plcId;
    private String plcName;
    private JSONObject plcNameJson;
    private Long robotId;
    private String robotName;
    private JSONObject robotNameJson;
    private Long elementId;
    private String elementName;
    private JSONObject elementNameJson;
    private Set<String> datColSet;
    private JSONObject alarmJson;
    private String appLang = LanguageBean.getInitLang();

    public void setLineNameJson(String strLineNameJson) {
        if (StringUtils.isNotBlank(strLineNameJson)) {
            this.lineNameJson = JSONObject.parseObject(strLineNameJson);
        } else {
            this.lineNameJson = null;
        }
    }

    public void setPlcNameJson(String strPlcNameJson) {
        if (StringUtils.isNotBlank(strPlcNameJson)) {
            this.plcNameJson = JSONObject.parseObject(strPlcNameJson);
        } else {
            this.plcNameJson = null;
        }
    }

    public void setRobotNameJson(String strRobotNameJson) {
        if (StringUtils.isNotBlank(strRobotNameJson)) {
            this.robotNameJson = JSONObject.parseObject(strRobotNameJson);
        } else {
            this.robotNameJson = null;
        }
    }

    public void setElementNameJson(String strElementNameJson) {
        if (StringUtils.isNotBlank(strElementNameJson)) {
            this.elementNameJson = JSONObject.parseObject(strElementNameJson);
        } else {
            this.elementNameJson = null;
        }
    }

    public void setAlarmJson(String strAlarmJson) {
        if (StringUtils.isNotBlank(strAlarmJson) && !StringUtils.equals(strAlarmJson, "{}")) {
            this.alarmJson = JSONObject.parseObject(strAlarmJson);
        } else {
            this.alarmJson = null;
        }
    }

    public void setDatColSet(String strDatColSet) {
        if (StringUtils.isNotBlank(strDatColSet)) {
            this.datColSet = new HashSet<String>(Arrays.asList(strDatColSet));
        } else {
            this.datColSet = null;
        }
    }
}
